package com.heiyu.api.response;

import com.heiyu.constants.CodeMsgEnum;
import com.heiyu.constants.ResponseMsgEnum;
import com.heiyu.utils.CodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * Created by mountain on 18/6/11.
 */
@ApiModel
public class BaseResponse<T extends ResponseModel> {

    @ApiModelProperty(name = "code",value = "请求状态码")
    private String code;
    @ApiModelProperty(name = "msg",value = "请求结果描述")
    private String msg;
    @ApiModelProperty(name="data",value = "业务数据对象")
    private T data;

    public BaseResponse(){
        code = CodeEnum.BUSSINESS_ERROR;
        msg = CodeMsgEnum.BUSSINESS_ERROR;
    }
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public  void success(){
        setCode(CodeEnum.SUCCESS);
        setMsg(CodeMsgEnum.SUCCESS);
    }


    public void systemError(){
        setCode(CodeEnum.SYSTEM_ERROR);
        setMsg(CodeMsgEnum.SYSTEM_ERROR);
    }

    public void businessError(){
        setCode(CodeEnum.BUSSINESS_ERROR);
        setMsg(CodeMsgEnum.BUSSINESS_ERROR);
    }

    public void error(String msg){
        if(msg.equals(ResponseMsgEnum.USER_NOT_LOGIN)){
            setCode(CodeEnum.LOGIN_LOST);
            setMsg(msg);
        }else{
            setCode(CodeEnum.BUSSINESS_ERROR);
            setMsg(msg);
        }
    }
}



